<!--{json width:"940",title:"修改帖子"}-->
<style type="text/css">
form.update_form dt {width: 5%;}
form.update_form dd {width: 93%;}
</style>
<form action="?post-update-fid-$fid-pid-$pid-ajax-1.htm" method="post" id="update_form_$pid" target="_blank" class="update_form">
	<input type="hidden" name="FORM_HASH" value="{FORM_HASH}" />
	<!--{hook common_form_hash_after.htm}-->
	<dl>
		<!--{hook post_update_subject_before.htm}-->
		<!--{if $isfirst}-->
		<dt>
			<label for="update_subject_$pid">标题：</label>
		</dt>
		<dd style="white-space: nowrap;">
			<!--{if $typeselect1}-->$typeselect1<!--{/if}-->
			<!--{if $typeselect2}-->$typeselect2<!--{/if}-->
			<!--{if $typeselect3}-->$typeselect3<!--{/if}-->
			<!--{if $typeselect4}-->$typeselect4<!--{/if}-->
			<input type="text" name="subject" id="update_subject_$pid" value="$thread[subject]" style="width: 600px;" /> <span class="small grey">(200字)</span>
		</dd>
		
		
		<!--{hook post_update_subject_after.htm}-->
		<dt><label for="coverimg">封面：</label></dt>
		<dd>
		<div class="bg1 border shadow">
			<div style="width: 400px; padding: 8px;">
				<div>
					
					<div  id="uploadInf" ><!--{if $thread[coverimg]}--><img src="$conf[image_url]$thread[coverimg]" height="300" /><!--{/if}--></div>
					<div id="preview"></div>
					<input type="file"  name="Filedata" id="coverimg" multiple />
					<input type="text" name="coverimg" id="valcoverimg" value="$thread[coverimg]" hidden />
					<div class="notice" id="notice" style="display: none;"></div>
				</div>
			</div>
		</div>
		</dd>
		<!--{/if}-->
		<dt><label for="update_message">内容：</label></dt>
		<dd style="position: relative;"><textarea name="message" id="update_message_$pid" style="width: 855px; height: 400px;">$post[message_html]</textarea></dd>
		
		<!--{hook post_update_message_after.htm}-->
		<!--{if $isfirst}-->
		<dt><label for="thread_tags_$pid">标签：</label></dt>
		<dd>
			<input type="text" id="tags_$pid" name="tags" value="$thread[tags]" style="width: 500px;" onkeyup="ReplaceDot(this)" /><span class="small grey">(逗号分隔)</span>
		</dd>
		<dt><label for="source">来源：</label></dt>
		<dd>$input[source]</dd>
		<!--<dt ><label for="publishtime">时间：</label></dt>
		<dd style="white-space: nowrap;width: 90%;">
			<input type="text" name="publishtime" id="subject_starttime_$pid" value="$thread[publishtime]" style="width: 100px;" > 
			<img src="view/image/datetimepicker/images/cal.gif" onclick="javascript:NewCssCal('subject_starttime_$pid','yyyyMMdd','dropdown',true,'24')" style="cursor:pointer"/>
			<span class="small grey">（设置文章发布时间,为空为立即发布）</span>
		</dd>-->
		<!--{/if}-->
		<dt></dt>
		<dd>
			<input type="submit" class="button bigblue" id="update_submit_$pid" value="编辑" />
			<input type="button" class="button biggrey" value="取消" id="update_cancel_$pid" />
			<!--{if $isfirst}--><input type="button" class="button bigblue" value="预览" id="post_thread_preview_$pid"  tabindex="104" /><!--{/if}-->
			<!--{hook post_update_button_end.htm}-->
		</dd>
	</dl>
</form>
<div class="dialog border shadow" title="预览" id="dialog1" style="background-color:#fff;display: none;"></div>
<!--{hook post_update_ajax_js_before.htm}-->

<script type="text/javascript">

function delay_execute(dialog, recall) {
	
	// hook post_update_delay_execute_start.htm
	
	$('#update_message_$pid')[0].focus();
	
	// 自动伸缩，自动提交
	$('#update_message_$pid').keyup(function(e) {
		if((e.ctrlKey && (e.which == 13 || e.which == 10)) || (e.altKey && e.which == 83)) {
			$('#update_submit_$pid').trigger('click');
			return false;
		}
	});
	
	$('#update_submit_$pid').click(function() {
		$('div.alert').remove();
		$('#update_submit_$pid').disable();
		var postdata = $("#update_form_$pid").serialize();
		$.post($('#update_form_$pid').attr('action'), postdata,  function(s){
			$('#update_submit_$pid').enable();
			
			var json = json_decode(s);
			if(error = json_error(json)) {alert(error); return false;}
			if(json.status <= 0) {alert(json.message); return false;}
			json = json.message;
			
			if(json.subject) {
				$('#update_subject_$pid').alert(json.subject).focus();
				return false;
			}
			if(json.message) {
				$('#update_message_$pid').parent().alert(json.message);
				$('#update_message_$pid')[0].focus();
				return false;
			}
			
			// hook post_update_submit_after_js.htm
			
			// 更新当前页面
<!--{if $isfirst}-->	$('#subject_$tid').html(json.subject_html);	<!--{/if}-->
 			$('#message_$pid').html(json.message_html);
 		
 			// 销毁编辑器
 			dialog.set_body('<div class="ok">编辑成功！</div>');
	 		setTimeout(function() {dialog.close();}, 500);
			
		});
		
		// hook post_update_ajax_post_after.htm
				 	
		return false;
	});
	
	$('#update_cancel_$pid').click(function() {
		dialog.close();
	});
	
	$('#post_thread_preview_$pid').click(function() {
		var coverimg = $("#valcoverimg").val();
		var body = '<link rel="stylesheet" type="text/css" href="view/preview.css">'+'<input type="button" class="button bigblue" value="4"   onclick="changepreview(480,320)" /><input type="button" class="button bigblue" value="5" onclick="changepreview(566,320);" /><input type="button" class="button bigblue" value="6"  onclick="changepreview(667,375);" /><input type="button" class="button bigblue" value="plus"  onclick="changepreview(960,540);" /><div class="rich_media_inner"><div id="page-content"><div id="img-content"class="rich_media_area_primary"><p style="text-align:center"><img src="$conf[image_url]'+coverimg+'" alt="" width="100%" \/></p>'
		+'<h2 class="rich_media_title">'+$("#update_subject_$pid").val()+'</h2>'+'<div class="rich_media_meta_list"><span class="rich_media_meta rich_media_meta_text">萌球宠物'+$("input[name='source']:checked")[0].nextSibling.nodeValue+'</span><span class="rich_media_meta rich_media_meta_text">$_user[username]</span><span class="rich_media_meta_text rich_media_meta_date">{php echo date("m-d H:i",$_SERVER[time])}</span></div></div></div></div><div class="rich_media_content">'+$("#update_message_$pid").val()+'</div>';
		$('#dialog1').dialog(
			{
				width: 320,
				height: 480,
				modal: false,
				open: true,
				closedestory: false,
				drag: true,
				position: 'left',
				fullicon: false,
				fullscreen: false,
				timeout: 0,
				showtitle: true,
				title: '',
				body: body,
				zIndex: 100
			}
		);
	});
	
	// hook post_update_delay_execute_end.htm
	
	// hook common_form_hash_after_js.htm
};

function changepreview(height,width){
	
	$('#dialog1').dialog({width:width,height:height+83});
	
}
</script>

<script type="text/javascript" src="view/js/zxxFile.js"></script>
<script type="text/javascript" >

//图片上传
var params = {
	fileInput: $("#coverimg").get(0),
	dragDrop: $("#fileDragArea").get(0),
	upButton: $("#coverimg").get(0),
	url: '?attach-uploadimage.htm',
	filter: function(files) {
		var arrFiles = [];
		for (var i = 0, file; file = files[i]; i++) {
			if (file.type.indexOf("image") == 0) {
				if (file.size >= 5120000) {
					alert('您这张"'+ file.name +'"图片大小过大，应小于500k');	
				} else {
					arrFiles.push(file);	
				}			
			} else {
				alert('文件"' + file.name + '"不是图片。');	
			}
		}
		return arrFiles;
	},
	onSelect: function(files) {
		var html = '', i = 0;
		$("#preview").html('<div class="upload_loading"></div>');
		var funAppendImage = function() {
			file = files[i];
			if (file) {
				var reader = new FileReader()
				reader.onload = function(e) {
					html = html + '<div id="uploadList_'+ i +'" class="upload_append_list">'+ 
						'<span id="uploadProgress_' + i + '" class="upload_progress"></span>' +
					'</div>';
					
					i++;
					funAppendImage();
				}
				reader.readAsDataURL(file);
			} else {
				$("#preview").html(html);
				if (html) {
					//删除方法
					$(".upload_delete").click(function() {
						ZXXFILE.funDeleteFile(files[parseInt($(this).attr("data-index"))]);
						return false;	
					});
					//提交按钮显示
					$("#fileSubmit").show();	
				} else {
					//提交按钮隐藏
					$("#fileSubmit").hide();	
				}
			}
		};
		funAppendImage();		
	},
	onDelete: function(file) {
		$("#uploadList_" + file.index).fadeOut();
	},
	onDragOver: function() {
		$(this).addClass("upload_drag_hover");
	},
	onDragLeave: function() {
		$(this).removeClass("upload_drag_hover");
	},
	onProgress: function(file, loaded, total) {
		var eleProgress = $("#uploadProgress_" + file.index), percent = (loaded / total * 100).toFixed(2) + '%';
		eleProgress.show().html(percent);
	},
	onSuccess: function(file, response) {
		$("#valcoverimg").val(response);
		$("#uploadInf").html('<img src="$conf[image_url]' + response +'" height="300" />');
	},
	onFailure: function(file) {
		$("#uploadInf").html("<p>图片" + file.name + "上传失败！</p>");	
		$("#uploadImage_" + file.index).css("opacity", 0.2);
	},
	onComplete: function() {
		//提交按钮隐藏
		$("#fileSubmit").hide();
		//file控件value置空
		$("#fileImage").val("");
	}
};
ZXXFILE = $.extend(ZXXFILE, params);
ZXXFILE.init();
</script>

<script type="text/javascript">
function ReplaceDot(obj)
{
var oldValue=obj.value;
while(oldValue.indexOf("，")!=-1)
{
obj.value=oldValue.replace("，",",");
oldValue=obj.value;
}
obj.value = oldValue;
}

</script>
